package com.ruoyi.project.business.tmppost.controller;

import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.framework.aspectj.lang.annotation.Log;
import com.ruoyi.framework.aspectj.lang.enums.BusinessType;
import com.ruoyi.framework.web.controller.BaseController;
import com.ruoyi.framework.web.model.AjaxResult;
import com.ruoyi.framework.web.page.TableDataInfo;
import com.ruoyi.project.business.tmppost.entity.TmpPost;
import com.ruoyi.project.business.tmppost.request.AddTmpPostRequest;
import com.ruoyi.project.business.tmppost.request.ListTmpPostRequest;
import com.ruoyi.project.business.tmppost.response.TmpPostResponse;
import com.ruoyi.project.business.tmppost.service.ITmpPostService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 临工岗位Controller
 * 
 * @author ${author}
 * @date 2024-04-01
 */
@RestController
@RequestMapping("/business/tmppost")
public class TmpPostController extends BaseController {
    @Autowired
    private ITmpPostService tmpPostService;

    /**
     * 查询临工岗位列表
     */
    @PreAuthorize("@ss.hasPermi('business:tmppost:list')")
    @GetMapping("/list")
    public TableDataInfo list(ListTmpPostRequest request) {
        startPage();
        Long tenantId = getTenantId();
        List<TmpPostResponse> list = tmpPostService.selectTmpPostList(request, tenantId);
        return getDataTable(list);
    }

    /**
     * 查询临工岗位列表
     */
    @GetMapping("/list-like-name")
    public TableDataInfo listLikeName(ListTmpPostRequest request) {
        startPage();
        Long tenantId = getTenantId();
        List<TmpPostResponse> list = tmpPostService.selectTmpPostList(request, tenantId);
        return getDataTable(list);
    }

    /**
     * 导出临工岗位列表
     */
    @PreAuthorize("@ss.hasPermi('business:tmppost:export')")
    @Log(title = "临工岗位", businessType = BusinessType.EXPORT)
    @GetMapping("/export")
    public AjaxResult export(ListTmpPostRequest request) {
        Long tenantId = getTenantId();
        List<TmpPostResponse> list = tmpPostService.selectTmpPostList(request, tenantId);
        ExcelUtil<TmpPostResponse> util = new ExcelUtil<>(TmpPostResponse.class);
        return util.exportExcel(list, "tmppost");
    }

    /**
     * 获取临工岗位详细信息
     */
    @PreAuthorize("@ss.hasPermi('business:tmppost:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id) {
        return AjaxResult.success(tmpPostService.selectTmpPostById(id));
    }

    /**
     * 新增临工岗位
     */
    @PreAuthorize("@ss.hasPermi('business:tmppost:add')")
    @Log(title = "临工岗位", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody AddTmpPostRequest request) {
        Long tenantId = getTenantId();
        Long operatorId = getUserId();
        return toAjax(tmpPostService.insertTmpPost(request, operatorId, tenantId));
    }

    /**
     * 修改临工岗位
     */
    @PreAuthorize("@ss.hasPermi('business:tmppost:edit')")
    @Log(title = "临工岗位", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody TmpPost tmpPost) {
        Long tenantId = getTenantId();
        Long operatorId = getUserId();
        return toAjax(tmpPostService.updateTmpPost(tmpPost, operatorId, tenantId));
    }

    /**
     * 删除临工岗位
     */
    @PreAuthorize("@ss.hasPermi('business:tmppost:remove')")
    @Log(title = "临工岗位", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids) {
        Long tenantId = getTenantId();
        Long operatorId = getUserId();
        return toAjax(tmpPostService.deleteTmpPostByIds(ids, operatorId, tenantId));
    }
}
